<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">

    <f:view contentType="text/html">
        <h:head>
            <f:facet name="first">
                <meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/>
                <title>PrimeFaces</title>
            </f:facet>
        </h:head>

        <h:body>






            <h:form id="formulario">
                <p:messages autoUpdate="true"/>
                <p:messages autoUpdate="true"/>

                <p:panel header="incluir Carro">
                    <h:panelGrid columns="2">
                        <h:outputText value="Marca:"/>
                        <p:inputText id="marca" value="#{carroMB.carro.marca}" />
                        <h:outputText value="Modelo:"/>
                        <p:inputText id="modelo" value="#{carroMB.carro.modelo}" />
                        <h:outputText value="Ano"/>
                        <p:inputText id="ano" value="#{carroMB.carro.ano}" maxlength="4" />
                        <h:outputText value="Preço:"/>
                        <p:inputText id="preco" value="#{carroMB.carro.preco}" />

                        <p:commandButton value="GRAVAR" action="#{carroMB.inserirCarro()}" update="tabelaCarros"/>
                        <p:commandButton value="Limprar" type="reset" />
                    </h:panelGrid>
                </p:panel>

                <p:dataTable id="tabelaCarros" value="#{carroMB.carros}" emptyMessage="Não foram encontrados itens." var="carro" paginator="true" rows="10">
                    <p:column headerText="Marca" filterBy="#{carro.marca}">
                        <h:outputText value="#{carro.marca}"/>
                    </p:column>
                    <p:column headerText="Modelo" filterBy="#{carro.modelo}">
                        <h:outputText value="#{carro.modelo}"/>
                    </p:column>
                    <p:column headerText="Ano">
                        <h:outputText value="#{carro.ano}"/>
                    </p:column>
                    <p:column headerText="Preço">
                        <h:outputText value="#{carro.preco}"/>
                    </p:column>
                    <p:column>
                        <p:commandButton  icon="ui-icon-close" title="REMOVER"   oncomplete="deleteDlg.show()" actionListener="#{carroMB.removerCarro(carro)}"  />
                    </p:column>
                </p:dataTable>


                <p:confirmDialog widgetVar="deleteDlg" id="deleteDialog" header="Delete #{carroMB.carro.marca}" message="Delete this #{carroMB.carro.ano} ?"
                                 width="400" showEffect="bounce" modal="true" closable="false" severity="alert">
                    <h:panelGroup layout="block" style="text-align: right">
                        <p:commandButton value="Yes" action="#{carroMB.removerCarro(carro)}" oncomplete="deleteDlg.hide();" update="tabelaCarros" />
                        <p:commandButton value="No" type="cancel" oncomplete="deleteDlg.hide();" />
                    </h:panelGroup>
                </p:confirmDialog>


            </h:form>








        </h:body>

    </f:view>
</html>

